﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>消息中心</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit">
    <link href="/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="/CSS/font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="/CSS/Base/BaseClass.css?cssver=4" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery-1.11.2.min.js"></script>
    <script src="/JqueryPlug/laypage/laypage.js"></script>
    <script src="/JqueryPlug/layer/layer/layer.js"></script>
    <script src="/Scripts/avalon.js"></script>
    <script src="/Scripts/SZHLCommon.js?jsver=5"></script>
    <style type="text/css">
        table tbody tr td i {
            cursor: pointer;
        }
         table tbody tr td a {
            cursor: pointer;
            text-decoration:none;
        }
    </style>
    <script>

        var model = avalon.define({
            $id: "CommonData",
            CommonData: [],
            SearchContent: "",
            selMenu: 0,
            ReadCount: 0,
            NoReadCount: 0,
            allStatus: 'Y',
            GetXXZXDataList: function (msgType) {
                model.selMenu = (msgType == "Y" ? 1 : 0);
                model.allStatus = (msgType == "Y" ? "N" : "Y");
                model.ModityBtn(msgType, $("#btnModify"));
                $.getJSON('/API/FTAPI.ashx?Action=GETXXZXIST_PAGE', { P1: msgType, P2: model.SearchContent, p: 1 }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        model.CommonData = resultData.Result;
                        laypage({
                            cont: 'pageDiv', //容器。值支持id名、原生dom对象，jquery对象。
                            pages: Math.ceil(parseInt(resultData.Result1) * 1.0 / 8), //通过后台拿到的总页数
                            curr: 1, //初始化当前页
                            jump: function (e) { //触发分页后的回调

                                $.getJSON('/API/FTAPI.ashx?Action=GETXXZXIST_PAGE', { P1: msgType, P2: model.SearchContent, p: e.curr }, function (resultData) {
                                    model.CommonData = resultData.Result;
                                })
                            }
                        });
                    }
                })
                model.GETXXCOUNT();

            }, ReadXX: function (item, dom, status) {

                var Ids = "";
                if (item == null && $(".fa").length == 0) {
                    return;//如果是标记本页状态，消息数量必须大于0
                }
                if (item == null && $(".fa").length > 0) {
                    $(".fa").each(function () {
                        Ids += $(this).prop("id") + ",";
                    })
                    Ids = Ids.length > 1 ? Ids.substring(0, Ids.length - 1) : Ids;
                }

                $.post("/API/FTAPI.ashx", { Action: "UPDTEREADSTATES", P1: item == null ? Ids : item.ID, s: status }, function (result) {
                    var jsonresult = $.parseJSON(result)
                    if ($.trim(jsonresult.ErrorMsg) != "") {
                        ComFunJS.winwarning(jsonresult.ErrorMsg);
                    } else {
                        var removeClass = "fa-square-o";
                        var addCla = "fa-check-square-o";
                        if (item == null) {
                            model.ModityBtn(status, dom);
                            if (model.allStatus == 'N') {
                                $(".fa").removeClass(addCla).addClass(removeClass)
                            } else {
                                $(".fa").removeClass(removeClass).addClass(addCla)
                            }
                            model.allStatus = model.allStatus == "Y" ? "N" : "Y";
                        } else {

                            if (status == 'N') {
                                $(dom).removeClass(addCla).addClass(removeClass)
                            } else {
                                $(dom).removeClass(removeClass).addClass(addCla)
                            }
                            item.isRead = status;
                        }
                        if (item != null) {
                            model.OpenDetail(item);
                        }
                        model.GETXXCOUNT();
                    }
                })
            },
            OpenDetail: function (item) {
                if (item.MsgLink) {
                    parent.ComFunJS.winviewform(item.MsgLink, "查看数据", "1000", "");
                }
            },
            GETXXCOUNT: function () {
                $.getJSON('/API/FTAPI.ashx?Action=GETXXCOUNT', function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        model.NoReadCount = resultData.Result;
                        model.ReadCount = resultData.Result1;
                    }
                })
            }, ModityBtn: function (status, dom) {
                var removeClass = "label-info";
                var addClass = "label-success";
                $(dom).text("标记本页消息为" + (status == "Y" ? "未" : "已") + "读").removeClass(status == "Y" ? addClass : removeClass).addClass(status == "Y" ? removeClass : addClass);
            }
        });
        avalon.ready(function () {
            model.GetXXZXDataList("N");
            model.GETXXCOUNT();
        })

    </script>
</head>
<body ms-controller="CommonData">
    <div class="container-fluid maindiv" style="margin-top: 20px" id="dvContent">
        <div style="width:120px;position:absolute">
            <ul class="list-group text-center  leftmenu ">
                <li class="list-group-item sel" ms-click="GetXXZXDataList('N')" ms-class-1="sel:selMenu==0">
                    <div>
                        <i class="iconfont hvr-grow">&#xe620;</i>
                        {{NoReadCount}}
                    </div>
                    <div>未读消息</div>
                </li>
                <li class="list-group-item" ms-click="GetXXZXDataList('Y')" ms-class-1="sel:selMenu==1" style="border-top:0;margin-top:2px">
                    <div>
                        <i class="iconfont hvr-grow">&#xe623;</i>
                        {{ReadCount}}
                    </div>
                    <div>已读消息</div>
                </li>
            </ul>
        </div>
        <div class="row contentdv" style="margin-left:121px">
            <div class="col-xs-12 ">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-xs-6">
                                <span class="label label-info" id="btnModify" style="cursor:pointer" ms-click="ReadXX(null,this,allStatus)">标记本页消息为已读</span>
                            </div>
                            <div class="col-xs-3">
                            </div>
                            <div class="col-xs-3">
                            </div>
                        </div>
                    </div>
                    <table class="table table-bordered table-hover table-striped">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th style="width:120px">消息类别</th>
                                <th style="width:70%">内容</th>
                                <th>时间</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ms-repeat-item="CommonData">
                                <td><i ms-click="ReadXX(item,this,item.isRead=='N'?'Y':'N')" ms-attr-id="item.ID" class="fa" ms-class-1="fa-square-o:item.isRead=='N'" ms-class-2="fa-check-square-o:item.isRead=='Y'"></i></td>
                                <td>{{item.MsgType}}</td>
                                <td><a ms-click="ReadXX(item,$(this).parent().find('i'),'Y')">{{item.MsgContent}}</a></td>
                                <td>{{item.CRDate|date("yyyy-MM-dd")}}</td>
                            </tr>
                        </tbody>
                    </table>

                </div>
                <div id="pageDiv" class="text-center"></div>
            </div>
        </div>
    </div>
    <script src="/CSS/bootstrap3.3.5/js/bootstrap.js"></script>
</body>
</html>
